/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kimstore.gui.repair;

import com.kimstore.bean.Item;
import com.kimstore.bean.ItemStatus;
import com.kimstore.bean.RepairDetail;
import com.kimstore.bean.Staff;
import com.kimstore.bean.User;
import com.kimstore.factory.DaoFactory;
import com.kimstore.gui.base.BaseWindow;
import com.kimstore.gui.main.CredentialsJOptionPane;
import com.kimstore.gui.main.Inventory;
import com.kimstore.utilities.DateUtil;
import com.kimstore.utilities.Session;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JOptionPane;

/**
 *
 * @author Administrator
 */
public class ViewItemForRepairWindow extends BaseWindow {

    private ViewItemForRepairController controller;
    private Item item;
    private List<Staff> staffs;
    private Float totalCost = 0.0f;
    private Float additionalCost = 0.0f;

    /**
     * Creates new form ViewItemForRepairWindow
     */
    public ViewItemForRepairWindow(ViewItemForRepairController controller) {
        initComponents();
        this.controller = controller;

        receiveDateDatePicker.getEditor().setEditable(false);
        JButton receiveDateButton = (JButton) receiveDateDatePicker.getComponent(1);
        receiveDateButton.setEnabled(false);

        releaseDateDatePicker.getEditor().setEditable(false);
        JButton releaseDateButton = (JButton) releaseDateDatePicker.getComponent(1);
        releaseDateButton.setEnabled(false);

        selectItemButton.setVisible(false);
        itemForReplacementField.setEnabled(false);
        itemForReplacementLabel.setEnabled(false);
    }

    public void populateWindow(Item item, List<Staff> staffs) {
        this.staffs = staffs;
        DefaultComboBoxModel model = (DefaultComboBoxModel) staffComboBox.getModel();
        for (Staff s : staffs) {
            model.addElement(s.getName());
        }

        this.item = item;
        itemField.setText(item.getSerial());
        productField.setText(item.getProduct().getName());
        if (item.getRepairDetail() != null) {
            RepairDetail r = item.getRepairDetail();
            staffComboBox.setSelectedItem(r.getStaff().getName());
            customerField.setText(r.getCustomerName());
            addressField.setText(r.getAddress());
            contactInformationField.setText(r.getContactInformation());
            emailAddressField.setText(r.getEmailAddress());

            Date receiveDate = r.getReceiveDate();
            if (receiveDate != null) {
                receiveDateDatePicker.setDate(receiveDate);
                receiveDateDatePicker.getEditor().setText(DateUtil.formatDate(receiveDate, "EEE MM/dd/yyyy"));
                receiveDateTimeField.setText(DateUtil.formatDate(receiveDate, "h:mm a"));
            }

            accessoriesField.setText(r.getAccessories());
            reasonsForRepairField.setText(r.getReasonForRepair());

            statusComboBox.setSelectedItem(r.getCurrentStatus());
            if (statusComboBox.getSelectedItem().toString().equals(ItemStatus.REPAIRED)) {
                partsCostField.setText(r.getPartsCost() + "");
                laborCostField.setText(r.getLaborCost() + "");
                additionalCostField.setText(r.getAdditionalCost() + "");
                verdictComboBox.setSelectedItem(r.getVerdict());
                workDoneField.setText(r.getWorkDone());
                if (r.getVerdict().equals(RepairDetail.REPLACEMENT)) {
                    itemForReplacementField.setText(r.getReplacement().getSerial() + " " + r.getReplacement().getProduct().getName());
                }
                Date releaseDate = r.getReleaseDate();
                if (releaseDate != null) {
                    releaseDateDatePicker.setDate(releaseDate);
                    releaseDateDatePicker.getEditor().setText(DateUtil.formatDate(releaseDate, "EEE MM/dd/yyyy"));
                    releaseDateTimeField.setText(DateUtil.formatDate(releaseDate, "h:mm a"));
                }
            }
        }
        toggleSecondTab(false);
    }

    private void nowReceiveDate() {
        Date date = new Date();
        receiveDateDatePicker.setDate(date);
        receiveDateDatePicker.getEditor().setText(DateUtil.formatDate(date, "EEE MM/dd/yyyy"));
        receiveDateTimeField.setText(DateUtil.formatDate(date, "h:mm a"));
    }

    private void nowReleaseDate() {
        Date date = new Date();
        releaseDateDatePicker.setDate(date);
        releaseDateDatePicker.getEditor().setText(DateUtil.formatDate(date, "EEE MM/dd/yyyy"));
        releaseDateTimeField.setText(DateUtil.formatDate(date, "h:mm a"));
    }

    private void done() {
        item.getRepairDetail().setAccessories(accessoriesField.getText());
        item.getRepairDetail().setAddress(addressField.getText());
        item.getRepairDetail().setContactInformation(contactInformationField.getText());

        item.getRepairDetail().setCustomerName(customerField.getText());
        item.getRepairDetail().setEmailAddress(emailAddressField.getText());
        item.getRepairDetail().setReasonForRepair(reasonsForRepairField.getText());
        item.getRepairDetail().setStaff(getStaff(staffComboBox.getSelectedItem() + ""));
        String date = DateUtil.formatDate(receiveDateDatePicker.getDate(), "MM/dd/yyyy");
        String time = receiveDateTimeField.getText();
        Date receiveDate = DateUtil.parseDate(date + " " + time, "MM/dd/yyyy h:mm a");
        item.getRepairDetail().setReceiveDate(receiveDate);

        if (statusComboBox.getSelectedItem().toString().equals(ItemStatus.REPAIRED) && (item.getRepairDetail().getCurrentStatus() != ItemStatus.REPAIRED)) {
            date = DateUtil.formatDate(releaseDateDatePicker.getDate(), "MM/dd/yyyy");
            time = releaseDateTimeField.getText();
            Date releaseDate = DateUtil.parseDate(date + " " + time, "MM/dd/yyyy h:mm a");
            item.getRepairDetail().setReleaseDate(releaseDate);
            item.getRepairDetail().setPartsCost(Float.parseFloat(partsCostField.getText()));
            item.getRepairDetail().setLaborCost(Float.parseFloat(laborCostField.getText()));
            item.getRepairDetail().setAdditionalCost(Float.parseFloat(additionalCostField.getText()));

            item.getRepairDetail().setVerdict(verdictComboBox.getSelectedItem().toString());
            item.getRepairDetail().setWorkDone(workDoneField.getText());

            item.addHistory(new ItemStatus(ItemStatus.REPAIRED, releaseDate, getStaff(staffComboBox.getSelectedItem().toString())));
        }
        item.getRepairDetail().setCurrentStatus(statusComboBox.getSelectedItem().toString());
        controller.fromWindow(item, verdictComboBox.getSelectedItem().toString());
        this.dispose();
    }

    private Staff getStaff(String name) {
        for (Staff s : staffs) {
            if (s.getName().equals(name)) {
                return s;
            }
        }
        return null;
    }

    private void toggle(boolean bool) {
        staffComboBox.setEnabled(bool);
        receiveDateDatePicker.getEditor().setEditable(bool);
        JButton receiveDateButton = (JButton) receiveDateDatePicker.getComponent(1);
        receiveDateButton.setEnabled(bool);
        receiveDateTimeField.setEditable(bool);
        receiveDateNowButton.setEnabled(bool);

        customerField.setEditable(bool);
        addressField.setEditable(bool);
        contactInformationField.setEditable(bool);
        emailAddressField.setEditable(bool);
        accessoriesField.setEditable(bool);
        reasonsForRepairField.setEditable(bool);
        //statusComboBox.setEnabled(bool);

        // Second Tab
        partsCostField.setEditable(bool);
        laborCostField.setEditable(bool);
        additionalCostField.setEditable(bool);
        workDoneField.setEditable(bool);

        verdictComboBox.setEnabled(bool);

        if (verdictComboBox.getSelectedItem().equals(RepairDetail.REPLACEMENT)) {
            selectItemButton.setVisible(bool);
        }

        releaseDateDatePicker.getEditor().setEditable(bool);
        JButton releaseDateButton = (JButton) releaseDateDatePicker.getComponent(1);
        releaseDateButton.setEnabled(bool);
        releaseDateTimeField.setEditable(bool);
        releaseDateNowButton.setEnabled(bool);
        
        saveButton.setEnabled(bool);
        cancelButton.setEnabled(bool);
    }

    private void toggleSecondTab(boolean bool) {

    }

    public void displayItemForRepair(Item item) {
        itemForReplacementField.setText(item.getSerial() + " " + item.getProduct().getName());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        emailAddressField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        itemField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        reasonsForRepairField = new javax.swing.JTextArea();
        jLabel4 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        customerField = new javax.swing.JTextField();
        addressField = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        productField = new javax.swing.JTextField();
        receiveDateDatePicker = new org.jdesktop.swingx.JXDatePicker();
        receiveDateTimeField = new javax.swing.JFormattedTextField();
        receiveDateNowButton = new javax.swing.JButton();
        staffComboBox = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        contactInformationField = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        accessoriesField = new javax.swing.JTextArea();
        jPanel2 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        partsCostField = new javax.swing.JFormattedTextField();
        jLabel13 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        workDoneField = new javax.swing.JTextArea();
        releaseDateDatePicker = new org.jdesktop.swingx.JXDatePicker();
        jLabel14 = new javax.swing.JLabel();
        releaseDateTimeField = new javax.swing.JFormattedTextField();
        releaseDateNowButton = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        statusComboBox = new javax.swing.JComboBox();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        laborCostField = new javax.swing.JFormattedTextField();
        additionalCostField = new javax.swing.JFormattedTextField();
        jLabel18 = new javax.swing.JLabel();
        totalCostField = new javax.swing.JFormattedTextField();
        jLabel19 = new javax.swing.JLabel();
        verdictComboBox = new javax.swing.JComboBox();
        selectItemButton = new javax.swing.JButton();
        itemForReplacementLabel = new javax.swing.JLabel();
        itemForReplacementField = new javax.swing.JTextField();
        saveButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        editButton = new javax.swing.JToggleButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("View Item for Repair");
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("sansserif", 1, 14)); // NOI18N
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/kimstore/resources/images/document-blue-icon-medium.png"))); // NOI18N
        jLabel1.setText("View Item for Repair");

        jLabel6.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabel6.setText("Accessories");

        emailAddressField.setEditable(false);
        emailAddressField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                emailAddressFieldActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabel2.setText("Staff");

        jLabel3.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabel3.setText("Item SKU");

        jLabel8.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabel8.setText("Product");

        itemField.setEditable(false);

        jLabel7.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabel7.setText("Reasons for Repair");

        reasonsForRepairField.setEditable(false);
        reasonsForRepairField.setColumns(20);
        reasonsForRepairField.setLineWrap(true);
        reasonsForRepairField.setRows(5);
        reasonsForRepairField.setWrapStyleWord(true);
        jScrollPane2.setViewportView(reasonsForRepairField);

        jLabel4.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabel4.setText("Customer Name");

        jLabel9.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabel9.setText("Address");

        customerField.setEditable(false);

        addressField.setEditable(false);

        jLabel5.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabel5.setText("Receive Date");

        productField.setEditable(false);

        receiveDateTimeField.setEditable(false);
        receiveDateTimeField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getTimeInstance(java.text.DateFormat.SHORT))));

        receiveDateNowButton.setText("Now");
        receiveDateNowButton.setEnabled(false);
        receiveDateNowButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                receiveDateNowButtonActionPerformed(evt);
            }
        });

        staffComboBox.setEnabled(false);
        staffComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                staffComboBoxActionPerformed(evt);
            }
        });

        jLabel11.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabel11.setText("Email Address");

        contactInformationField.setEditable(false);
        contactInformationField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                contactInformationFieldActionPerformed(evt);
            }
        });

        jLabel10.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabel10.setText("Contact Information");

        accessoriesField.setEditable(false);
        accessoriesField.setColumns(20);
        accessoriesField.setLineWrap(true);
        accessoriesField.setRows(5);
        accessoriesField.setWrapStyleWord(true);
        jScrollPane1.setViewportView(accessoriesField);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING)))
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(customerField, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(productField, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(itemField, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(staffComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(addressField, javax.swing.GroupLayout.Alignment.TRAILING)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(12, 12, 12)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(receiveDateDatePicker, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(receiveDateTimeField, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(receiveDateNowButton)
                                .addGap(0, 203, Short.MAX_VALUE))
                            .addComponent(contactInformationField, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(emailAddressField)
                            .addComponent(jScrollPane1)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING))))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(staffComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(itemField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(productField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(customerField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(addressField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(contactInformationField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(emailAddressField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(receiveDateDatePicker, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(receiveDateNowButton)
                    .addComponent(receiveDateTimeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(77, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Complaint Information", jPanel1);

        jLabel12.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabel12.setText("Parts Cost");

        partsCostField.setEditable(false);
        partsCostField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00"))));
        partsCostField.setText("0.0");
        partsCostField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                partsCostFieldKeyReleased(evt);
            }
        });

        jLabel13.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabel13.setText("Work Done");

        workDoneField.setEditable(false);
        workDoneField.setColumns(20);
        workDoneField.setLineWrap(true);
        workDoneField.setRows(5);
        workDoneField.setWrapStyleWord(true);
        jScrollPane3.setViewportView(workDoneField);

        jLabel14.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabel14.setText("Release Date");

        releaseDateTimeField.setEditable(false);
        releaseDateTimeField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getTimeInstance(java.text.DateFormat.SHORT))));

        releaseDateNowButton.setText("Now");
        releaseDateNowButton.setEnabled(false);
        releaseDateNowButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                releaseDateNowButtonActionPerformed(evt);
            }
        });

        jLabel15.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabel15.setText("Status");

        statusComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "In Repair", "Repaired" }));
        statusComboBox.setEnabled(false);
        statusComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                statusComboBoxItemStateChanged(evt);
            }
        });
        statusComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                statusComboBoxActionPerformed(evt);
            }
        });

        jLabel16.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabel16.setText("Labor Cost");

        jLabel17.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabel17.setText("Additional Cost");

        laborCostField.setEditable(false);
        laborCostField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00"))));
        laborCostField.setText("0.00");
        laborCostField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                laborCostFieldKeyReleased(evt);
            }
        });

        additionalCostField.setEditable(false);
        additionalCostField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00"))));
        additionalCostField.setText("0.00");
        additionalCostField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                additionalCostFieldKeyReleased(evt);
            }
        });

        jLabel18.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabel18.setText("Total Cost");

        totalCostField.setEditable(false);
        totalCostField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00"))));

        jLabel19.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabel19.setText("Verdict");

        verdictComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Pull Out", "Replacement", "Release", "Refund" }));
        verdictComboBox.setEnabled(false);
        verdictComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                verdictComboBoxItemStateChanged(evt);
            }
        });
        verdictComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                verdictComboBoxActionPerformed(evt);
            }
        });

        selectItemButton.setText("Select Item for Replacement");
        selectItemButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selectItemButtonActionPerformed(evt);
            }
        });

        itemForReplacementLabel.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        itemForReplacementLabel.setText("Item");

        itemForReplacementField.setEditable(false);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(itemForReplacementLabel)
                    .addComponent(jLabel19)
                    .addComponent(jLabel17)
                    .addComponent(jLabel16)
                    .addComponent(jLabel15)
                    .addComponent(jLabel13)
                    .addComponent(jLabel12)
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(verdictComboBox, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(statusComboBox, javax.swing.GroupLayout.Alignment.LEADING, 0, 153, Short.MAX_VALUE)
                            .addComponent(partsCostField, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(laborCostField, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(additionalCostField, javax.swing.GroupLayout.Alignment.LEADING))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel18)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(totalCostField))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(selectItemButton)
                                .addGap(0, 123, Short.MAX_VALUE))))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(releaseDateDatePicker, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(releaseDateTimeField, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(releaseDateNowButton))
                            .addComponent(itemForReplacementField, javax.swing.GroupLayout.PREFERRED_SIZE, 354, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 133, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(statusComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19)
                    .addComponent(verdictComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(selectItemButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(itemForReplacementLabel)
                    .addComponent(itemForReplacementField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(partsCostField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(jLabel18)
                    .addComponent(totalCostField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(laborCostField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(additionalCostField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel13)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(releaseDateDatePicker, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(releaseDateTimeField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(releaseDateNowButton))
                .addContainerGap(37, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Repair Information", jPanel2);

        saveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/kimstore/resources/images/done.png"))); // NOI18N
        saveButton.setText("Save");
        saveButton.setEnabled(false);
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        cancelButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/kimstore/resources/images/cancel.png"))); // NOI18N
        cancelButton.setText("Cancel");
        cancelButton.setEnabled(false);
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        editButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/kimstore/resources/images/pen-write-icon.png"))); // NOI18N
        editButton.setText("Edit Repair Details ");
        editButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING)
            .addComponent(jTabbedPane1)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(editButton))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(saveButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelButton)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(editButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 553, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saveButton)
                    .addComponent(cancelButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void receiveDateNowButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_receiveDateNowButtonActionPerformed
        nowReceiveDate();
    }//GEN-LAST:event_receiveDateNowButtonActionPerformed

    private void emailAddressFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_emailAddressFieldActionPerformed
        this.dispose();
    }//GEN-LAST:event_emailAddressFieldActionPerformed

    private void staffComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_staffComboBoxActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_staffComboBoxActionPerformed

    private void contactInformationFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_contactInformationFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_contactInformationFieldActionPerformed

    private void releaseDateNowButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_releaseDateNowButtonActionPerformed
        nowReleaseDate();
    }//GEN-LAST:event_releaseDateNowButtonActionPerformed

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        done();
    }//GEN-LAST:event_saveButtonActionPerformed

    private void verdictComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_verdictComboBoxActionPerformed
    }//GEN-LAST:event_verdictComboBoxActionPerformed

    private void statusComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_statusComboBoxActionPerformed
        if (statusComboBox.getSelectedItem().toString().equals(ItemStatus.REPAIRED)) {
            toggleSecondTab(true);
        } else {
            toggleSecondTab(false);
        }
    }//GEN-LAST:event_statusComboBoxActionPerformed

    private void laborCostFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_laborCostFieldKeyReleased
        if (!laborCostField.getText().trim().isEmpty()) {
            float parts = Float.parseFloat(partsCostField.getText());
            float labor = Float.parseFloat(laborCostField.getText());
            float additional = Float.parseFloat(additionalCostField.getText());
            totalCost = parts + labor + additional;

            totalCostField.setText(totalCost + "");
        }
    }//GEN-LAST:event_laborCostFieldKeyReleased

    private void additionalCostFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_additionalCostFieldKeyReleased
        if (!additionalCostField.getText().trim().isEmpty()) {
            float parts = Float.parseFloat(partsCostField.getText());
            float labor = Float.parseFloat(laborCostField.getText());
            float additional = Float.parseFloat(additionalCostField.getText());
            totalCost = parts + labor + additional;

            totalCostField.setText(totalCost + "");
        }
    }//GEN-LAST:event_additionalCostFieldKeyReleased

    private void partsCostFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_partsCostFieldKeyReleased
        if (!partsCostField.getText().trim().isEmpty()) {
            float parts = Float.parseFloat(partsCostField.getText());
            float labor = Float.parseFloat(laborCostField.getText());
            float additional = Float.parseFloat(additionalCostField.getText());
            totalCost = parts + labor + additional;

            totalCostField.setText(totalCost + "");
        }
    }//GEN-LAST:event_partsCostFieldKeyReleased

    private void statusComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_statusComboBoxItemStateChanged
        if (statusComboBox.getSelectedItem().toString().equals(ItemStatus.REPAIRED)) {
            toggleSecondTab(true);
        } else {
            toggleSecondTab(false);
        }
        System.out.println("HHAHAHAHAHAHA");
    }//GEN-LAST:event_statusComboBoxItemStateChanged

    private void verdictComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_verdictComboBoxItemStateChanged
        if (verdictComboBox.getSelectedItem().toString().equals(RepairDetail.REPLACEMENT)) {
            if(editButton.isSelected()) {
                selectItemButton.setVisible(true);
                itemForReplacementField.setEnabled(true);
                itemForReplacementLabel.setEnabled(true);
            }
        } else {
            if(editButton.isSelected()) {
                selectItemButton.setVisible(false);
                itemForReplacementField.setEnabled(false);
                itemForReplacementLabel.setEnabled(false);
            }
        }
    }//GEN-LAST:event_verdictComboBoxItemStateChanged

    public void addAdditionalCost(float cost) {
        this.additionalCost += cost;
        additionalCostField.setText(this.additionalCost.toString());

        float parts = Float.parseFloat(partsCostField.getText());
        float labor = Float.parseFloat(laborCostField.getText());
        float additional = Float.parseFloat(additionalCostField.getText());
        totalCost = parts + labor + additional;

        totalCostField.setText(totalCost + "");
    }

    private void selectItemButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectItemButtonActionPerformed
        controller.createSelectReplacementItemController();

    }//GEN-LAST:event_selectItemButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        this.dispose();
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed
        if (Session.getInstance().getUser().getType() != User.TYPE_ADMIN && Session.getInstance().getUser().getType() != User.TYPE_ADMIN_B) {
            CredentialsJOptionPane pane = new CredentialsJOptionPane(this);

            if (pane.showDialog() == JOptionPane.OK_OPTION) {
                String username = pane.getUsernameField().getText();
                String password = Arrays.toString(pane.getPasswordField().getPassword());

                User user = DaoFactory.getInstance().getUserDao().findByUsernamePassword(username, password);
                if (user != null && (user.getType() == User.TYPE_ADMIN || user.getType() == User.TYPE_ADMIN_B)) {
                    if (editButton.isSelected()) {
                        toggle(true);
                        statusComboBox.setEnabled(true);
                        if (statusComboBox.getSelectedItem().toString().equals(ItemStatus.REPAIRED)) {
                            toggleSecondTab(true);
                        }
                    } else {
                        toggle(false);
                        statusComboBox.setEnabled(false);
                        toggleSecondTab(false);
                    }
                } else {
                    editButton.setSelected(false);
                }
            } else {
                editButton.setSelected(false);
            }
        } else {
            if (editButton.isSelected()) {
                toggle(true);
                statusComboBox.setEnabled(true);
                if (statusComboBox.getSelectedItem().toString().equals(ItemStatus.REPAIRED)) {
                    toggleSecondTab(true);
                }
            } else {
                toggle(false);
                statusComboBox.setEnabled(false);
                toggleSecondTab(false);
            }
        }
    }//GEN-LAST:event_editButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea accessoriesField;
    private javax.swing.JFormattedTextField additionalCostField;
    private javax.swing.JTextField addressField;
    private javax.swing.JButton cancelButton;
    private javax.swing.JTextField contactInformationField;
    private javax.swing.JTextField customerField;
    private javax.swing.JToggleButton editButton;
    private javax.swing.JTextField emailAddressField;
    private javax.swing.JTextField itemField;
    private javax.swing.JTextField itemForReplacementField;
    private javax.swing.JLabel itemForReplacementLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JFormattedTextField laborCostField;
    private javax.swing.JFormattedTextField partsCostField;
    private javax.swing.JTextField productField;
    private javax.swing.JTextArea reasonsForRepairField;
    private org.jdesktop.swingx.JXDatePicker receiveDateDatePicker;
    private javax.swing.JButton receiveDateNowButton;
    private javax.swing.JFormattedTextField receiveDateTimeField;
    private org.jdesktop.swingx.JXDatePicker releaseDateDatePicker;
    private javax.swing.JButton releaseDateNowButton;
    private javax.swing.JFormattedTextField releaseDateTimeField;
    private javax.swing.JButton saveButton;
    private javax.swing.JButton selectItemButton;
    private javax.swing.JComboBox staffComboBox;
    private javax.swing.JComboBox statusComboBox;
    private javax.swing.JFormattedTextField totalCostField;
    private javax.swing.JComboBox verdictComboBox;
    private javax.swing.JTextArea workDoneField;
    // End of variables declaration//GEN-END:variables


    private void unusedFunction () {
        /*
        if (Session.getInstance().getUser().getType() != User.TYPE_ADMIN && Session.getInstance().getUser().getType() != User.TYPE_ADMIN_B && Session.getInstance().getUser().getType() != User.TYPE_TECHNICAL) {
            CredentialsJOptionPane pane = new CredentialsJOptionPane(this);

            if (pane.showDialog() == JOptionPane.OK_OPTION) {
                String username = pane.getUsernameField().getText();
                String password = Arrays.toString(pane.getPasswordField().getPassword());

                User user = DaoFactory.getInstance().getUserDao().findByUsernamePassword(username, password);
                if (user != null && (user.getType() == User.TYPE_ADMIN || user.getType() == User.TYPE_ADMIN_B)) {
                    if (updateToggleButton.isSelected()) {
                        statusComboBox.setEnabled(true);
                        if (statusComboBox.getSelectedItem().toString().equals(ItemStatus.REPAIRED)) {
                            toggleSecondTab(true);
                        }
                        saveButton.setEnabled(true);
                        cancelButton.setEnabled(true);
                        editButton.setEnabled(false);
                    } else {
                        statusComboBox.setEnabled(false);
                        toggleSecondTab(false);
                        saveButton.setEnabled(false);
                        cancelButton.setEnabled(false);
                        editButton.setEnabled(true);

                    }
                } else {
                    updateToggleButton.setSelected(false);
                }
            } else {
                updateToggleButton.setSelected(false);
            }
        } else {
            if (updateToggleButton.isSelected()) {
                statusComboBox.setEnabled(true);
                if (statusComboBox.getSelectedItem().toString().equals(ItemStatus.REPAIRED)) {
                    toggleSecondTab(true);
                }
                saveButton.setEnabled(true);
                cancelButton.setEnabled(true);
                editButton.setEnabled(false);

            } else {
                statusComboBox.setEnabled(false);
                toggleSecondTab(false);
                saveButton.setEnabled(false);
                cancelButton.setEnabled(false);
                editButton.setEnabled(true);
            }
        }
        */
    }
    
}
